<template>
	<div id="cardexamine" class="same-change-oldstyle">
		<div class="same-head-box">
			<div class="saem-seat-box">
				<div class="saem-seat-left">
					<span>当前位置：</span>
					<el-breadcrumb separator-class="el-icon-arrow-right">
						<el-breadcrumb-item>水卡管理</el-breadcrumb-item>
						<el-breadcrumb-item>普通水卡</el-breadcrumb-item>
						<el-breadcrumb-item>线上实体卡申请记录</el-breadcrumb-item>
					</el-breadcrumb>
				</div>
				<div class="saem-seat-right">
					<button class="same-search-btns same-search-export" @click="exportExcel">导出</button>
					<button class="same-search-btns same-search-export" @click="RefreshFun">刷新</button>
					<!-- <button class="same-search-btns" @click="returnBack">返回</button>	 -->
				</div>
			</div>
			<div class="same-search-box">
				<div>
					<div class="same-search-left">
						<div class="same-left-one">
							<span class="same-search-span same-search-fisrt">申请时间:</span>
							<el-date-picker style="width:140px" v-model="start_time" type="date" size="medium"
								value-format="yyyy-MM-dd" placeholder="开始时间"></el-date-picker>
							<div class="same-interval">至</div>
							<el-date-picker style="width:140px" v-model="end_time" type="date" size="medium" value-format="yyyy-MM-dd"
								placeholder="结束时间"></el-date-picker>
						</div>
						<div class="same-left-one">
							<span class="same-search-span">水卡号:</span>
							<el-input size="medium" v-model="cardNum" type="Number" placeholder="请输入水卡号" style="width: 160px;">
							</el-input>
						</div>
						<div class="same-left-one">
							<span class="same-search-span">所属园区:</span>
							<el-input size="medium" v-model="village_name" placeholder="请输入园区名称" style="width: 160px;"></el-input>
						</div>
						<div class="same-left-one" v-if="!moveShow">
							<div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">更多查询条件<i
									:class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>
							<el-button type="primary" size="medium" @click="serach()">搜索</el-button>
							<el-button type="info" size="medium" @click="reset()">重置</el-button>
						</div>
					</div>
					<div class="same-search-right"></div>
				</div>
				<!-- 搜索更多 -->
				<div>
					<div class="same-search-left  new-sear-height" ref="leftHeight">
						<div class="same-left-one">
							<span class="same-search-span">所属省市区:</span>
							<el-select size="medium" v-model="province_id" placeholder="请选择省份" @change="chooseProvince"
								style="width:140px;">
								<el-option v-for="item in Province" :key="item.province" :label="item.province_name"
									:value="item.province"></el-option>
							</el-select>
							<el-select size="medium" v-model="city_id" placeholder="请选择城市" @change="chooseCity" style="width:140px;">
								<el-option v-for="item in City" :key="item.city" :label="item.city_name" :value="item.city"></el-option>
							</el-select>
							<el-select size="medium" v-model="area_id" placeholder="请选择区县" @change="chooseArea" style="width:140px;">
								<el-option v-for="item in Area" :key="item.area" :label="item.area_name" :value="item.area"></el-option>
							</el-select>
						</div>
						<div class="same-left-one">
							<span class="same-search-span">审核状态:</span>
							<el-select size="medium" v-model="value" placeholder="请选择" style="width: 140px;">
								<el-option v-for="item in selected" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</div>
						<div class="same-left-one" :class="[moveShow?'':'new-sear-opacity']">
							<div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">收起更多查询条件<i
									:class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>
							<el-button type="primary" size="medium" @click="serach()">搜索</el-button>
							<el-button type="info" size="medium" @click="reset()">重置</el-button>
						</div>
					</div>
					<div class="same-search-right"></div>
				</div>
			</div>
		</div>

		<div class="same-table-box">
			<!--<h4 class="same-title-box">-->
			<!--线上申请实体卡-->
			<!--</h4>-->
			<div class="table_box">

				<div class="common-table-outer">
					<el-table class="common-table" v-loading="loading" header-cell-class-name="common-table-header-cell"
						:data="tableData" stripe>
						<el-table-column header-align="center" width="70" align="center" label="序号">
							<template slot-scope="scope">
								{{scope.$index+1+(pageNo-1)*pageSize}}
							</template>
						</el-table-column>
						<el-table-column align="center" prop="full_name" label="用户">
						</el-table-column>
						<el-table-column align="center" prop="tel" label="手机号码">
						</el-table-column>
						<el-table-column align="center" label="水卡卡号">
							<template slot-scope="scope">
								<!-- filtersCard -->
								{{ scope.row.card_number }}
							</template>
						</el-table-column>
						<el-table-column align="center" prop="audit_status" label="办理状态">
						</el-table-column>

						<el-table-column align="center" prop="audit_time" label="办理时间">
						</el-table-column>

						<el-table-column align="center" prop="village_name" label="所属园区">
						</el-table-column>

						<el-table-column align="center" prop="apply_time" label="申请时间">
						</el-table-column>

						<el-table-column width="220" align="center" prop="ctime" label="操作">
							<template slot-scope="scope">
								<el-link class="custom-link" @click="handleEditPass(scope.row.id)" v-if="scope.row.audit_status == '审核中'">审核</el-link>
								<el-link  class="custom-link" @click="handleEditShow(scope.row.id)" >查看</el-link>
								<el-link  class="custom-link" @click="changeapply(scope.row.id)" v-if="scope.row.audit_status == '审核中'">修改</el-link>
							</template>
						</el-table-column>
						<template slot="empty" v-if="isLoad">
							<div class="new-no-data-show">
								<img src="../../assets/images/no-data.png" alt="">
								<div>暂无相关数据</div>
							</div>
						</template>
					</el-table>

					<div class="same-page-inShow" v-if="tableData.length > 0 && isLoad">
						<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
							:current-page.sync="pageNo" :page-sizes="pageSizesList" :page-size="pageSize"
							layout="total, prev, pager, next, jumper, sizes" :total="totalDataNumber"></el-pagination>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import { regionDataPlus } from 'element-china-area-data';
	export default {
		name: 'cardexamine',
		data: function () {
			return {
				pageNo: 1,
				pageSize: 15,
				pageSizesList: [15, 30, 40, 50],
				tableData: [], //返回的结果集合
				totalDataNumber: 0, //数据的总数,
				loading: true,
				time: '',
				options: regionDataPlus,
				selected: [
					{
						value: '0',
						label: '全部'
					},
					{
						value: '1',
						label: '审核中'
					},
					{
						value: '2',
						label: '审核通过'
					},
					{
						value: '3',
						label: '审核拒绝'
					}
				],
				value: '',
				start_time: '',
				end_time: '',
				audit_status: '',
				cardNum: '', //之后为新的+
				Province: [],
				City: [],
				Area: [],
				Village: [],
				province_id: '',
				city_id: '',
				area_id: '',
				village_id: '',
				village_name: '',
				isLoad: false, //是否请求接口
				moveBtn: false,//是否暂时更多查询条件按钮按钮 搜索条件控制
				moveShow: false,//是否开启动画
				scrollHeight: '',//需要监听的高度
			};
		},
		// 初始化执行方法
		created: function () {
			this.$emit('gitHidden', true);//是否隐藏底部版权 true 隐藏 
			var that = this;
			var pageSize = that.pageSize; // 每页显示条数
			var page = 1; // 当前页
			that.pageNo = 1;
			that.waterCardList(page, pageSize, that.start_time, that.end_time); // 获取申请实体卡审核列表
			that.getProvince(); //获取省份
		},
		inject: ['reload'],
		methods: {
			RefreshFun() {
				// 调用reload方法，刷新整个页面
				this.reload()
			},
			//返回
			returnBack() {
				this.$router.back(-1);
			},
			exportExcel: function () {
				var that = this;
				var start_time = that.start_time;
				var end_time = that.end_time;
				that.$post({
					url: 'Partner/WaterCard/exportWaterCardAudit',
					data: {
						start_time: start_time ? start_time : '',
						end_time: end_time ? end_time : '',
						audit_status: that.audit_status,
						province: that.province_id,
						city: that.city_id,
						area: that.area_id,
						card_class: 2,
						card: that.cardNum,
						village_name: that.village_name
					},
					success: data => {
						if (data.code < 0) {
							this.$message({
								showClose: true,
								message: data.data.message,
								center: true
							});
						}
						var $form = $('<form method="GET"></form>');
						$form.attr('action', data.data);
						$form.appendTo($('body'));
						$form.submit();
					}
				});
			},
			// 三级联动
			// handleChange(value) {},
			// 分页
			handleSizeChange(val) {
				var that = this;
				that.pageNo = 1;
				that.pageSize = val; // 当前每页显示条数
				that.waterCardList(that.pageNo, that.pageSize, that.start_time, that.end_time); // 获取申请实体卡审核列表
			},
			// 当前页
			handleCurrentChange(val) {
				var that = this;
				that.pageNo = val;
				that.waterCardList(val, that.pageSize, that.start_time, that.end_time); // 获取申请实体卡审核列表
			},
			//点击查看
			handleEditShow(index) {
				this.$router.push({ path: '/lookCardMsg', query: { id: index } });
			},
			// 点击编辑
			handleEditPass(index) {
				this.$router.push({ path: '/lookCardEdit', query: { id: index } });
			},
			//点击修改
			changeapply(index) {
				this.$router.push({ path: '/changeapply', query: { id: index } });
			},
			// 点击充值
			handleTopUp() {
				this.$router.push({ path: '/cardrecharge' });
			},
			// 获取申请实体卡审核列表
			waterCardList: function (page, pageSize, start_time, end_time) {
				var that = this;
				that.loading = false; //开启动画
				that.isLoad = true;
				that.$post({
					url: 'Partner/WaterCard/accountAuditList',
					data: {
						row: pageSize,
						page: page,
						start_time: start_time ? start_time : '',
						end_time: end_time ? end_time : '',
						audit_status: that.audit_status,
						province: that.province_id,
						city: that.city_id,
						area: that.area_id,
						card: that.cardNum,
						card_class: 2,
						village_name: that.village_name
					},
					success: data => {
						that.isLoad = true;
						that.loading = false; //关闭动画
						if (data.code == 1000) {
							that.tableData = data.data.data;
							that.totalDataNumber = Number(data.data.page.total_number); // 总的数据
						} else {
							this.$message({
								type: 'warning',
								showClose: true,
								message: data.message,
								center: true
							});
						}
					}
				});
			},

			reset() {
				this.start_time = '';
				this.end_time = '';
				this.province_id = '';
				this.city_id = '';
				this.area_id = '';
				this.village_name = '';
				this.value = '';
				this.cardNum = '';
				this.pageNo = 1;
				this.audit_status = '';
				this.waterCardList(this.pageNo, this.pageSize);
			},
			// 搜索
			serach: function () {
				var that = this;
				var province_id = this.province_id;
				var city_id = this.city_id;
				var area_id = this.area_id;
				console.log('数据>>>>>', province_id, city_id, area_id);
				this.village_name = this.village_name;
				this.audit_status = this.value;
				that.pageNo = 1; // 当前页
				this.waterCardList(that.pageNo, that.pageSize, that.start_time, that.end_time);
			},
			/*newnew...................................................*/
			chooseProvince(val) {
				this.getCity(val);
				this.city_id = '';
				this.area_id = '';
			},
			chooseCity(val) {
				this.getArea(val);
				this.area_id = '';
			},
			chooseArea(val) { },
			//三级联动-省
			getProvince() {
				this.$post({
					url: 'Partner/Village/getEqProvince',
					data: {},
					success: data => {
						this.Province = data.data;
						console.log('数据数据数据');
					}
				});
			}, //三级联动-市
			getCity(id) {
				this.$post({
					url: 'Partner/Village/getEqCity',
					data: {
						id: id
					},
					success: data => {
						this.City = data.data;
					}
				});
			}, //三级联动-区/县
			getArea(id) {
				this.$post({
					url: 'Partner/Village/getEqArea',
					data: {
						id: id
					},
					success: data => {
						this.Area = data.data;
					}
				});
			}, //园区列表
			// getVillage(id) {
			//   this.$post({
			//     url: 'Common/Common/getAllVillage',
			//     data: {
			//       province: this.province_id,
			//       city: this.city_id,
			//       area: this.area_id,
			//       village_name: ''
			//     },
			//     success: (data) => {
			//       this.Village = data.data;
			//     }
			//   })
			// }, //园区搜索+
			searchVillage() { },
			//此处获取高度必须在dom元素创建完成之后才能获取
			gitHeight() {
				//  let clientHeight=this.$refs.leftHeight.clientHeight;
				let scrollHeight = this.$refs.leftHeight.scrollHeight;
				this.scrollHeight = scrollHeight;
				scrollHeight <= 30 ? this.moveBtn = false : this.moveBtn = true;

			},
			openMore() {
				this.moveShow = !this.moveShow;
				this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
			},
		},
		mounted() {
			this.gitHeight();
			//监听高度变化 
			var that = this;
			window.addEventListener("resize", function () {
				let scrollHeight = that.$refs.leftHeight && that.$refs.leftHeight.scrollHeight ? that.$refs.leftHeight.scrollHeight : that.scrollHeight;
				that.scrollHeight = scrollHeight;
			});
		},
		watch: {
			// 如果 `scrollHeight` 发生改变，这个函数就会运行 此处是为了防止用户缩小屏幕导致页面显示不全
			scrollHeight: function (val) {
				this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
			}
		},

		activated() {
			if (this.$route.meta.isUpdate) {
				this.tableData = [];
				this.waterCardList(this.pageNo, this.pageSize)
				this.$route.meta.isUpdate = false;
			}
		},

		beforeRouteEnter(to, from, next) {
			let updates = ["/lookCardEdit", "/changeapply"]
			if (updates.includes(from.path)) {
				to.meta.isUpdate = true;
			}
			next();
		},
		beforeRouteLeave(to, from, next) {
			let updates = ["/lookCardEdit", "/changeapply","/lookCardMsg"];
			if (!updates.includes(to.path)) {
				from.meta.keepAlive = false; 
			} else {
				from.meta.keepAlive = true;
			}
			next();
		}
	};
</script>
<style>
	#cardexamine {
		width: 100%;
		height: 100%;
		background: #FFFFFF;
	}
</style>